package hr_project.hr.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpResponse;
import org.apache.http.impl.io.HttpResponseWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import hr_project.hr.biz.Right.IRightBiz;
import hr_project.hr.entity.Right;

@Controller
@RequestMapping("/right")
public class RightAction {

	@Autowired
	private IRightBiz biz;

	public IRightBiz getBiz() {
		return biz;
	}

	public void setBiz(IRightBiz biz) {
		this.biz = biz;
	}
	
	
	//所有权限的列表给超级管理员使用
	@RequestMapping("/list")
	@ResponseBody
	public List<Right> list(){
		return biz.getParentRight();
	}
	
	@RequestMapping("/add")
	@ResponseBody
	public void add(Right rig,HttpServletResponse res){
		biz.addRight(rig);
		try {
			res.getWriter().print("ok");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@RequestMapping("/del")
	@ResponseBody
	public void del(long id,HttpServletResponse res){
		System.out.println("传进来了啊："+id);
		biz.delRight(id);
		try {
			res.getWriter().print("ok");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//	//根据权限id查找一个权限
	@RequestMapping("/getbyid")
	@ResponseBody
	public Right getbyid(long id){
		return biz.getByid(id);
	}
	
	//权限修改
	@RequestMapping("/mod")
	@ResponseBody
	public void mod(Right rig,HttpServletResponse res){
		biz.modRight(rig);
		try {
			res.getWriter().print("ok");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
}
